<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
    <head th:replace="/common/include :: header(~{::title}, ~{::link}, ~{::style})">
        <title>站点配置</title>
        <link th:href="@{/lib/bootstrap-fileinput/fileinput.css}" rel="stylesheet" type="text/css"/>
        <link th:href="@{/lib/bootstrap-fileinput/theme.min.css}" rel="stylesheet" type="text/css"/>
        <link th:href="@{/lib/bootstrap-fileinput/explorer-fas/theme.min.css}" rel="stylesheet" type="text/css"/>
    </head>
    <body class="white-bg" style="font: 14px Helvetica Neue, Helvetica, PingFang SC, 微软雅黑, Tahoma, Arial, sans-serif !important;">
        <section class="section-content">
            <div class="row">
                <th:block th:include="/common/breadcrumb :: breadcrumb"/>
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <div class="nav-tabs-custom">
                            <ul class="nav nav-tabs">
                                <li class="active"><a href="#sites" data-toggle="tab" aria-expanded="true">网站信息</a></li>
                                <li><a href="#config" data-toggle="tab" aria-expanded="false">功能配置</a></li>
                                <li class="pull-right"><i class="fa fa-cogs"></i></li>
                            </ul>
                            <div class="tab-content">
                                <!-- 站点信息 -->
                                <div class="tab-pane active" id="sites">
                                    <form class="form-horizontal" id="form-sites">
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">服务器地址：</label>
                                            <div class="col-sm-6">
                                                <input type="text" class="form-control" name="system_address" placeholder="http://localhost/piece-api">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">桌面客户端版本：</label>
                                            <div class="col-sm-3">
                                                <input type="text" class="form-control" name="pc_version">
                                            </div>
                                            <div class="col-sm-3">
                                                <button type="button" class="btn btn-success btn-rounded btn-sm" onclick="initUpload('desktop')" data-toggle="modal" data-target="#uploadFileModal" data-backdrop="static">
                                                    <i class="fa fa-plus"></i> 桌面客户端
                                                </button>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">移动客户端版本：</label>
                                            <div class="col-sm-3">
                                                <input type="text" class="form-control" name="app_version">
                                            </div>
                                            <div class="col-sm-3">
                                                <button type="button" class="btn btn-success btn-rounded btn-sm" onclick="initUpload('mobile')" data-toggle="modal" data-target="#uploadFileModal" data-backdrop="static">
                                                    <i class="fa fa-plus"></i> 移动客户端
                                                </button>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">版权信息：</label>
                                            <div class="col-sm-6">
                                                <input type="text" class="form-control" name="copyright">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">文件管理器根路径：</label>
                                            <div class="col-sm-6">
                                                <input type="text" class="form-control" name="storage_root_path" placeholder="linux系统：/，windows系统：d:">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">单页应用状态：</label>
                                            <div class="col-sm-6">
                                                <label class="radio-box">
                                                    <input type="radio" name="system_single_page" value="true"/>
                                                    <div class="control-label ml5">开启</div>
                                                </label>
                                                <label class="radio-box">
                                                    <input type="radio" name="system_single_page" value="false" default-value="false" checked/>
                                                    <div class="control-label ml5">关闭</div>
                                                </label>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">导航栏状态：</label>
                                            <div class="col-sm-6">
                                                <label class="radio-box">
                                                    <input type="radio" name="system_breadcrumb_enable" value="true"/>
                                                    <div class="control-label ml5">开启</div>
                                                </label>
                                                <label class="radio-box">
                                                    <input type="radio" name="system_breadcrumb_enable" value="false" default-value="false" checked/>
                                                    <div class="control-label ml5">关闭</div>
                                                </label>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">使用用例状态：</label>
                                            <div class="col-sm-6">
                                                <label class="radio-box">
                                                    <input type="radio" name="system_demo_enable" value="true"/>
                                                    <div class="control-label ml5">开启</div>
                                                </label>
                                                <label class="radio-box">
                                                    <input type="radio" name="system_demo_enable" value="false" default-value="false" checked/>
                                                    <div class="control-label ml5">关闭</div>
                                                </label>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <div class="col-sm-offset-2 col-sm-4">
                                                <button type="button" class="btn btn-sm btn-success form-submit" onclick="clearIndex()"><i class="fa fa-refresh"></i>重置索引</button>
                                                <button type="button" class="btn btn-sm btn-success form-submit" onclick="saveSites()"><i class="fa fa-check"></i>保 存</button>
                                            </div>
                                        </div>
                                    </form>
                                </div>

                                <!-- 站点信息 -->
                                <div class="tab-pane" id="config">
                                    <form class="form-horizontal" id="form-config">
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">审计日志状态：</label>
                                            <div class="col-sm-6">
                                                <label class="radio-box">
                                                    <input type="radio" name="system_log_enable" value="true"/>
                                                    <div class="control-label ml5">启用</div>
                                                </label>
                                                <label class="radio-box">
                                                    <input type="radio" name="system_log_enable" value="false" default-value="false" checked/>
                                                    <div class="control-label ml5">禁用</div>
                                                </label>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">单点登陆状态：</label>
                                            <div class="col-sm-6">
                                                <label class="radio-box">
                                                    <input type="radio" name="system_auth_login_kick" value="true"/>
                                                    <div class="control-label ml5">启用</div>
                                                </label>
                                                <label class="radio-box">
                                                    <input type="radio" name="system_auth_login_kick" value="false" default-value="false" checked/>
                                                    <div class="control-label ml5">禁用</div>
                                                </label>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">并发人数限制：</label>
                                            <div class="col-sm-2">
                                                <input type="number" class="form-control" name="system_auth_token_maximum" min="1">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">访问时长监控：</label>
                                            <div class="col-sm-6">
                                                <label class="radio-box">
                                                    <input type="radio" name="system_time_watch_enable" value="true"/>
                                                    <div class="control-label ml5">启用</div>
                                                </label>
                                                <label class="radio-box">
                                                    <input type="radio" name="system_time_watch_enable" value="false" default-value="false" checked/>
                                                    <div class="control-label ml5">禁用</div>
                                                </label>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">黑名单监控：</label>
                                            <div class="col-sm-6">
                                                <label class="radio-box">
                                                    <input type="radio" name="system_black_enable" value="true"/>
                                                    <div class="control-label ml5">启用</div>
                                                </label>
                                                <label class="radio-box">
                                                    <input type="radio" name="system_black_enable" value="false" default-value="false" checked/>
                                                    <div class="control-label ml5">禁用</div>
                                                </label>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">黑名单监控规则：</label>
                                            <div class="col-sm-2">
                                                统计时长（秒）
                                                <input type="number" class="form-control" name="system_black_limit_time">
                                            </div>
                                            <div class="col-sm-2">
                                                限制次数
                                                <input type="number" class="form-control" name="system_black_limit_count">
                                            </div>
                                            <div class="col-sm-2">
                                                锁定分钟
                                                <input type="number" class="form-control" name="system_black_block_time">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">XSS验证规则：</label>
                                            <div class="col-sm-6 m-b-sm">
                                                忽略地址
                                                <textarea class="form-control" rows="3" name="xss_exclude_url"></textarea>
                                            </div>
                                            <div class="col-sm-offset-2 col-sm-6">
                                                非法参数
                                                <textarea class="form-control" rows="3" name="xss_illegal_param"></textarea>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">消息重推次数：</label>
                                            <div class="col-sm-2">
                                                <input type="number" class="form-control" name="system_message_retry" min="0">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">验证码规则：</label>
                                            <div class="col-sm-2 m-b-sm">
                                                类型
                                                <input type="text" class="form-control" name="kaptcha_type" placeholder="char, math">
                                            </div>
                                            <div class="col-sm-2">
                                                图片宽度
                                                <input type="number" class="form-control" name="kaptcha_img_width">
                                            </div>
                                            <div class="col-sm-2">
                                                图片高度
                                                <input type="number" class="form-control" name="kaptcha_img_height">
                                            </div>
                                            <div class="col-sm-2">
                                                字符个数
                                                <input type="number" class="form-control" name="kaptcha_length">
                                            </div>
                                            <div class="col-sm-2">
                                                短信字符个数
                                                <input type="number" class="form-control" name="sms_kaptcha_length">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">无需验证码客户端：</label>
                                            <div class="col-sm-2">
                                                <input type="text" class="form-control" name="client_ignore_validate">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">邮箱配置：</label>
                                            <div class="col-sm-10 m-b-sm">
                                                主机
                                                <input type="text" class="form-control" name="mail_host">
                                            </div>
                                            <div class="col-sm-offset-2 col-sm-3 m-b-sm">
                                                地址
                                                <input type="text" class="form-control" name="mail_from">
                                            </div>
                                            <div class="col-sm-3">
                                                密码
                                                <input type="text" class="form-control" name="mail_password">
                                            </div>
                                            <div class="col-sm-offset-2 col-sm-6">
                                                注册邮件验证
                                                <label class="radio-box">
                                                    <input type="radio" name="register_email_enable" value="true"/>
                                                    <div class="control-label ml5">启用</div>
                                                </label>
                                                <label class="radio-box">
                                                    <input type="radio" name="register_email_enable" value="false" default-value="false" checked/>
                                                    <div class="control-label ml5">禁用</div>
                                                </label>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <div class="col-sm-offset-2 col-sm-4">
                                                <button type="button" class="btn btn-sm btn-success form-submit" onclick="saveConfig()"><i class="fa fa-check"></i>保 存</button>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="modal inmodal" id="uploadFileModal" tabindex="-1" role="dialog" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content animated bounceInRight">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal">
                                <span aria-hidden="true">&times;</span><span class="sr-only">关闭</span>
                            </button>
                            <h4>附件上传</h4>
                        </div>
                        <div class="modal-body">
                            <div class="form-group">
                                <div class="file-loading">
                                    <input id="file-upload" name="file" type="file"/>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <div th:replace="/common/include :: footer"></div>
        <div th:replace="/common/include :: fileinputJs"></div>

        <script th:inline="javascript">
            var prefix = ctx + 'api/site';

            $(function () {
                loadSites();
            });

            function loadSites() {
                // 表单赋值
                $.operate.get({
                    url: prefix + '/load',
                    success: function(result) {
                        if (result.code == 200) {
                            $.form.load('form-sites', result.param);
                            $.form.load('form-config', result.param);
                        } else {
                            $.modal.toast.error(result.msg, result.param);
                        }
                    },
                    error: function(result) {
                        window.location.href = ctx + 'error/500';
                    }
                });
            }

            function saveSites() {
                save('form-sites');
            }

            function initUpload(type) {
                $('#file-upload').off('fileuploaded');

                // 加载上传按钮组件
                $.fileInputPlug.init('file-upload', null, {
                    theme: 'fa',
                    uploadUrl: ctx + 'api/file/upload',
                    uploadExtraData: {
                        'path': '/mnt/storage/Soft',
                        'fileType': type
                    },
                    initialPreviewAsData: false,
                    minFileCount: 1,
                    maxFileCount: 1,
                    showDownload: false
                });
                $('#file-upload').on('fileuploaded', function(event, data) {
                    $('#file-upload').fileinput('clear');
                    $('#uploadFileModal').modal('hide');
                    $.modal.toast.success('上传成功');
                    try {
                        $('#file-upload').fileinput('destroy');
                    } catch (e) {
                        // console.log(e);
                    }
                });
            }

            function clearIndex() {
                $.operate.confirm(ctx + 'api/blog/manage/clearIndex', null, '确定重建站点索引吗？这可能会消耗大量时间');
            }

            function saveConfig() {
                save('form-config');
            }

            function save(from_id) {
                var param = $.form.serialize(from_id);
                $.ajax({
                    url: prefix + '/save',
                    type: 'post',
                    dataType: 'json',
                    data: param,
                    success: function (result) {
                        if (result.code == 200) {
                            $.modal.toast.success(result.msg);
                        } else {
                            $.modal.toast.error(result.msg, result.param);
                        }
                    }
                });
            }
        </script>
    </body>
</html>
